package com.alibaba.apm;

import brave.Span;
import brave.Tracing;

import java.io.IOException;

import static java.lang.System.exit;

public class ZipkinManualDemo {


    // 获取traceing（包括上报数据网关等信息）
    Tracing tracing = TracingConfig.getTracing();

    public static void main(String[] args) {
        System.out.println("begin tracing");
        ZipkinManualDemo test2 = new ZipkinManualDemo();
        test2.firstBiz();
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void firstBiz() {
        // 创建rootspan
        tracing.tracer().startScopedSpan("parentSpan");
        Span span =  tracing.tracer().currentSpan();
        span.tag("key", "firstBiz");
        secondBiz();
        span.finish();
    }

    private void secondBiz() {
        tracing.tracer().startScopedSpanWithParent("childSpan", tracing.tracer().currentSpan().context());
        Span chindSpan =  tracing.tracer().currentSpan();
        chindSpan.tag("key", "secondBiz");
        chindSpan.finish();
        System.out.println("end tracing,id:" + chindSpan.context().traceIdString());
    }

}
